// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    

    @property(cc.Sprite)
    aircraft1: cc.Sprite = null;

    @property(cc.Sprite)
    aircraft2: cc.Sprite = null;


   

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        //当手指触点落在目标节点区域内时。
        this.aircraft1.node.on('touchstart',this.onTouch,this)

        //当手指在屏幕上移动时。      
        this.aircraft1.node.on('touchmove',this.onTouchMove,this)
        //当手指在目标节点区域内离开屏幕时。
        this.aircraft1.node.on('touchend',this.onTouchEnd,this)
        //当手指在目标节点区域外离开屏幕时。
        this.aircraft1.node.on('touchcancel',this.onTouchCancel,this)


        //当手指触点落在目标节点区域内时。
        this.aircraft2.node.on('touchstart',this.onTouch1,this)

        //当手指在屏幕上移动时。      
        this.aircraft2.node.on('touchmove',this.onTouchMove1,this)
        //当手指在目标节点区域内离开屏幕时。
        this.aircraft2.node.on('touchend',this.onTouchEnd1,this)
        //当手指在目标节点区域外离开屏幕时。
        this.aircraft2.node.on('touchcancel',this.onTouchCancel1,this)


       


        

    }
    onTouch(e : cc.Event.EventTouch){
        //cc.log("点击到 并显示触发位置"+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())
    }

    //会重叠两个精灵体
    onTouchMove(e : cc.Event.EventTouch){
        this.aircraft1.node.x=e.getLocationX()
        
        this.aircraft1.node.y=e.getLocationY()
        //cc.log("拖拽到 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())
    }


    //会重叠两个精灵体
    onTouchEnd(e : cc.Event.EventTouch){
        this.aircraft1.node.x=e.getLocationX()
       
        this.aircraft1.node.y=e.getLocationY()
        //cc.log("松手了 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())
    }

    onTouchCancel(e : cc.Event.EventTouch){
        //cc.log("离开屏幕 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())

    }

    onTouch1(e : cc.Event.EventTouch){
        //cc.log("点击到 并显示触发位置"+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())
    }

   
    onTouchMove1(e : cc.Event.EventTouch){
       



        this.aircraft2.node.x=e.getLocationX()
        
        this.aircraft2.node.y=e.getLocationY()
        //cc.log("拖拽到 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())

    }


    
    onTouchEnd1(e : cc.Event.EventTouch){
    


        this.aircraft2.node.x=e.getLocationX()
       
        this.aircraft2.node.y=e.getLocationY()
        //cc.log("松手了 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())
    }

    onTouchCancel1(e : cc.Event.EventTouch){
        //cc.log("离开屏幕 "+"x值是"+e.getLocationX(),"y值是"+e.getLocationY())

    }

    start () {

    }

    update (dt) {


        
        
        


    }
}
